package com.moyun.zbmy.zizhou.ui.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.text.TextUtils;
import android.util.Pair;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.githang.statusbar.StatusBarCompat;
import com.moyun.zbmy.zizhou.application.Cache;
import com.moyun.zbmy.zizhou.base.BaseDetailActivity;
import com.moyun.zbmy.zizhou.beans.FNews;
import com.moyun.zbmy.zizhou.beans.ShareEvent;
import com.moyun.zbmy.zizhou.ui.utils.TitleUtils;
import com.ruihang.generalibrary.ui.dialog.ShareFragment;
import com.ruihang.generalibrary.ui.widget.CustomFontTextView;
import com.moyun.zbmy.zizhou.R;
import com.moyun.zbmy.zizhou.base.BaseActivity;
import com.moyun.zbmy.zizhou.ui.fragment.TvFragment;
import com.ruihang.generalibrary.utils.UrlUtils;

import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;


public class TVActivity extends BaseDetailActivity {
    @BindView(R.id.title_top_layout_edit)
    protected CustomFontTextView share;
    @BindView(R.id.title_top_logo_layout)
    protected LinearLayout title_top_logo_layout;
    @BindView(R.id.title_top_title)
    protected CustomFontTextView title_top_title;
    @BindView(R.id.title_top_layout_back)
    protected ImageView title_top_layout_back;
    public View statusBarView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tv);
        ButterKnife.bind(this);
        if (!TextUtils.isEmpty(getIntent().getStringExtra(BaseActivity.EX_URL))) {

            Bundle bundle = new Bundle();
            TvFragment fragment = new TvFragment();
            bundle.putString(BaseActivity.EX_URL, getIntent().getStringExtra(BaseActivity.EX_URL));
            bundle.putInt(BaseActivity.EX_ID, getIntent().getIntExtra(BaseActivity.EX_ID, 0));

            if (!TextUtils.isEmpty(getIntent().getStringExtra(BaseActivity.EX_DATA)) && getIntent().getStringExtra(BaseActivity.EX_DATA).equals("jiajiao")) {
                bundle.putString(BaseActivity.EX_DATA,"jiajiao");

            }

            //    fragment.setChannelUrl(getIntent().getStringExtra(BaseActivity.EX_URL));
            fragment.setArguments(bundle);
            getSupportFragmentManager()
                    .beginTransaction()
                    .add(R.id.fragment_container, fragment)
                    .commit();

        }


    }


    @OnClick({R.id.title_top_layout_back, R.id.title_top_layout_edit})
    protected void OnClick(View view) {
        if (view.getId() == R.id.title_top_layout_back) {
            finish();
        } else if (view.getId() == R.id.title_top_layout_edit) {
            //TODO 频道分享
            if(Cache.getInstance().getShareInfo()!=null){
                if (!TextUtils.isEmpty(Cache.getInstance().getShareInfo().getSharedUrl())) {

                    FNews fNews = new FNews();

                    fNews.setNewsShareUrl(Cache.getInstance().getShareInfo().getSharedUrl());
                    fNews.setNewsTitle(Cache.getInstance().getShareInfo().getTitle());

                    showShareFragment(fNews, new ShareFragment.OnShareFragmentClickListener() {
                        @Override
                        public void onClick(Pair<String, String> pair) {

                        }
                    });

                }

            }
        }
    }


}
